#pragma once
#include "C_Widget.h"
#include "C_ListItem.h"
#include "C_TextButton.h"

namespace gui
{
	class C_List :
		public C_Widget
	{
	private:
		int m_countShow;
		int m_listSize;
		int m_currentList;
		std::vector<C_ListItem*> m_items;

		C_Widget m_wgItems;
		C_Widget m_wgTop;
		C_Label  m_lbCount;
		C_TextButton m_tbNextPage;
		C_TextButton m_tbPreviousPage;

		C_ListItem* m_selectedItem;
	public:
		C_List();
		virtual ~C_List();

		void	setCountShow(int c) { m_countShow = c; updateList(); updateRender(); }
		int		countShow()			{ return m_countShow;			 }

		void makeItem(std::wstring t, void* data) { this->addItem(new C_ListItem(t, data)); }
		void addItem(C_ListItem* item) { m_items.push_back(item); item->setList(this); updateList(); updateRender(); }

		inline void updateList() { m_listSize = ceil((float)m_items.size() / m_countShow); }
		void updateRender();
		/////////////////////////////////////////////////////////////////////////////////
		/////////////////	VIRTUAL FUNCTION
		virtual void renderWidget();
		virtual void syncWidgets();

		int			itemsSize() { return m_items.size(); }
		C_ListItem* getItemById(int i) { return m_items[i]; }
		void		removeItem(int i) { m_items.erase(m_items.begin() + i); }
		void		selectToNull() { m_selectedItem = nullptr; }


		inline void setSelectItem(C_ListItem* item) 
		{ 
			if (m_selectedItem != nullptr)	m_selectedItem->setSelect(false);
			m_selectedItem = item;			item->setSelect(true);
		}
		C_ListItem* selectedItem() { return m_selectedItem; }
		void cmd_nextPage();
		void cmd_previousPage();
	};
}

